package com.kuangstudy.controller;

import com.kuangstudy.service.prize.DrowPrizeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author renyitong
 * @version 1.0.0
 * @createTime 2023年09月18日
 * @Description
 */
@RestController
@Api(tags = "抽奖【一等、二等、三等】")
public class DrowPrizeController {

    @Autowired
    private DrowPrizeService drowPrizeService;

    /**
     * 抽出指定的用户获得奖品
     *
     * @param userNum 用户人数
     * @return
     */
    @PostMapping("/user/drow/prize")
    @ApiOperation("抽出指定的用户获得奖品")
    public String userDrowPrize(@RequestParam("userNum") Integer userNum) {
        if (userNum <= 0) {
            throw new RuntimeException("抽奖人数不能小于等于0");
        }
        List<Integer> myList = drowPrizeService.drowPrize(userNum);
        String collect = myList.stream().map(s -> String.valueOf(s)).collect(Collectors.joining(","));
        return "活得奖品的用户是: " + collect;
    }

}
